package com.sinosoft.dsp.component.bpm.viewbean.activity.part;

import com.sinosoft.dsp.component.bpm.service.core.BpmSelectItemsService;
import com.sinosoft.dsp.component.bpm.util.ProcessParse;
import com.sinosoft.dsp.component.bpm.viewbean.BpmJpdlDefineViewBean;
import com.sinosoft.dsp.component.bpm.viewbean.activity.IBpmActivityPartEditViewBean;
import com.sinosoft.dsp.system.core.exception.SinoException;
import com.sinosoft.dsp.system.core.log.Log;
import com.sinosoft.dsp.system.to.IGenericTO;
import com.sinosoft.dsp.system.to.attribute.Attribute;
import com.sinosoft.dsp.system.to.helper.ToHelper;
import com.sinosoft.dsp.system.utils.Const;
import com.sinosoft.dsp.system.utils.ReflectionUtils;

public class BpmActivityEndBaseViewBean extends BpmActivityCommonBaseViewBean
		implements IBpmActivityPartEditViewBean {

	private static final Log log = Log.getLog(BpmActivityEndBaseViewBean.class
			.getName());

	// 结束方式
	public static final String FIELD_ENDS = "ends";

	// 结束状态
	public static final String FIELD_END_STATE = "endState";

	@Override
	public void init(IGenericTO tos) throws SinoException {
		super.init(tos);

		// 活动对象
		Attribute<?> name = ToHelper.getContentAttriubteByName(tos,
				BPM_NODE_NAME);
		String nameStr = name.convertToString();

		BpmJpdlDefineViewBean pvb = (BpmJpdlDefineViewBean) this.getParent()
				.getParent();
		org.jbpm.xsdobject.Process process = pvb.getProcess();
		Object obj = ProcessParse.getActivity(process, nameStr);

		try {
			String desc = (String) ReflectionUtils.invokeGetMethod(obj,
					FIELD_ENDS);
			this.addField(FIELD_ENDS, Const.NVL(desc,
					BpmSelectItemsService.SELECT_ITEM_ENDS_DEFAULT));
		} catch (Exception e) {
			log.debug("无法获得结束方式。");
		}

		try {
			String state = (String) ReflectionUtils.invokeGetMethod(obj,
					"state");
			this.addField(FIELD_END_STATE, Const.NVL(state, ""));
		} catch (Exception e) {
			log.debug("无法获得结束状态。");
		}
	}
}
